<template>
  <div class="LunaCard" :style="countBC" @click="handleClick">
    <div class="bc" :style="{ 'box-shadow': 'inset 0px 0px 16px 0px' + activeBackgroundColor }"></div>
    <input ref="copyInput" class="copyInput" :value="bc" readonly />
    <div class="BarArea">
      <div>
        <span>R</span>
        <div class="colorBar">
          <div class="ActiveBar" :style="{ width: (rgbBarLength[0] / 255) * 100 + '%' }"></div>
        </div>
      </div>
      <div>
        <span>G</span>
        <div class="colorBar">
          <div class="ActiveBar" :style="{ width: (rgbBarLength[1] / 255) * 100 + '%' }"></div>
        </div>
      </div>
      <div>
        <span>B</span>
        <div class="colorBar">
          <div class="ActiveBar" :style="{ width: (rgbBarLength[2] / 255) * 100 + '%' }"></div>
        </div>
      </div>
      <div>
        <span>C</span>
        <div class="colorBar">
          <div class="ActiveBar" :style="{ width: cmykBarLength[0] + '%' }"></div>
        </div>
      </div>
      <div>
        <span>M</span>
        <div class="colorBar">
          <div class="ActiveBar" :style="{ width: cmykBarLength[1] + '%' }"></div>
        </div>
      </div>
      <div>
        <span>Y</span>
        <div class="colorBar">
          <div class="ActiveBar" :style="{ width: cmykBarLength[2] + '%' }"></div>
        </div>
      </div>
      <div>
        <span>K</span>
        <div class="colorBar">
          <div class="ActiveBar" :style="{ width: cmykBarLength[3] + '%' }"></div>
        </div>
      </div>
    </div>
    <div class="CardTextArea">
      <h1>{{ name }}</h1>
      <p>{{ bc }}</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ColorCard',
  props: {
    name: {
      type: String,
      default: '颜色'
    },
    bc: {
      type: String,
      default: '#FFFFFF'
    },
    activeBackgroundColor: {
      type: String,
      default: '#FFFFFF'
    },
    rgbBarLength: {
      type: Array,
      default: () => {
        return [1, 1, 1]
      }
    },
    cmykBarLength: {
      type: Array,
      default: () => {
        return [1, 1, 1, 1]
      }
    }
  },
  computed: {
    countBC() {
      return { 'background-color': this.bc, 'box-shadow': '0 0 48px' + this.bc }
    }
  },
  methods: {
    handleClick() {
      //获取input对象
      const input = this.$refs.copyInput
      //选中input标签
      input.select()
      //执行复制
      document.execCommand('copy')
      window.getSelection().empty()
      this.$emit('on-click', this.bc)
    }
  }
}
</script>

<style scoped lang="scss">
.LunaCard {
  display: inline-block;
  content-visibility: auto;
  width: 200px;
  height: 323px;
  position: relative;
  border-radius: 36px;
  cursor: pointer;
  transition: all 0.5s;
  //margin-right: 40px;
  //margin-bottom: 88px;
  flex-shrink: 0;
  .bc {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 36px;
    transition: all 0.5s ease-in;
  }
  .BarArea {
    width: 116px;
    position: absolute;
    top: 16px;
    left: 16px;
    > div {
      text-align: left;
      display: flex;
      align-items: center;
      span {
        display: inline-block;
        width: 20px;
        text-align: center;
      }
      > div {
        width: 100%;
        height: 4px;
        background: rgba(0, 0, 0, 0.1);
        margin-left: 8px;
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
        position: relative;
        div {
          position: absolute;
          top: 0;
          left: 0;
          background: #fff;
          height: 4px;
        }
      }
    }
  }
  .CardTextArea {
    position: absolute;
    bottom: 12px;
    right: 12px;
    writing-mode: vertical-rl;
    text-align: right;
    h1 {
      letter-spacing: 12px;
      font-size: 24px;
      text-shadow: 0 0 2px #696969;
    }
    p {
      font-size: 16px;
      text-shadow: 0 0 2px #696969;
    }
  }
  &:hover {
    transform: scale(1.1);
  }
  .copyInput {
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
  }
}
@media (max-width: 450px) {
  .LunaCard {
    width: 160px;
    margin-right: 0;
  }
}
</style>
